package com.fan.leetcode;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @author ZhangFan
 * @since 2021/7/17 下午 12:41
 */
public class QuestionOffer42 {
    public int maxSubArray(int[] nums) {
        List<Integer> list = new ArrayList<>();
        int sum = 0;
        for (int num : nums) {
            sum += num;
            list.add(sum);
        }
        Integer max = list.stream().max(Comparator.naturalOrder()).get();
        Integer min = list.stream().min(Comparator.naturalOrder()).get();
        return max-min;
    }
}
